SetAxisCamSwitch
使用轴位置来控制触发数位输出的开关,当轴达到特定的位置,开关即开启或关闭,而开关可受轴的向前或向厚运动控制。
语法
KsCommandStatus SetAxisCamSwitch(
int Index,
int SwitchLength,
McCamSwitch* Switches,
int TrackLength,
McOutput* Outputs,
McTrack* Tracks,
DWORD EnableMask,
McSource ValueSource
);
参数
Index [in]:轴索引。索引以零为起点;别名将影响此参数。
SwitchLength [in]:在开关阵列的开关数量,每一轨道最多可有八个开关。
Switches [in]:控制开关动作,轨道数量必须依照顺序排列。请见 McCamSwitch 结构。
TrackLength [in]:轨道阵列中的轨道数量,输出与轨道的长度必须一致。例如,有两个输出就必须有两个轨道,最多可有 32 个轨道。
Outputs [in]:选择对应轨道所控制的数位输出。请见 McOutput 结构。
Tracks [in]:将补偿时间和迟滞添加到轨道上的开关,TrackNumber 定义在 Switches 中。请见 McTrack 结构。
EnableMask [in]:启用不同轨道,此参数为 BOOL 32 位元,当 BOOL 值设为一时将启动轨道阵列中的相应轨道。
ValueSource [in]:定义轴值的来源,例如:位置。请见 McSource 类型。
- mcCommandedValue, mcSetValue-同步设定值。建议使用此设定。
- mcActualValue-同步实际值。此设定可能不稳定。
回传值
返回 KsCommandStatus 结构。
备注
- McCamSwitch 为指定供应商的结构,用于定义数位凸轮的开关。
- McOutput 为连接至(实体)输出的指定供应商结构,若使用本身伺服驱动器的数位输出 (DO),需在 Start 前使用 EnableAxisOutput。
- McTrack 为包含轨道属性的指定供应商结构,例如:每个轨道的补偿时间(轨道是一组与一个输出相关的开关), 亦可包含输出的引用。
- 此功能有时被称作 PLS-阶段、位置或可编程极限开关 (Phase or Position or Programmable Limit Switch)。
- 当模数轴启用时,模数值会套用至 McCamSwitch 中的 FirstOnPosition 与 LastOnPosition。为了避免潜在问题,建议将 FirstOnPosition 与 LastOnPosition(补偿后)放在同一区段内,且不跨越模数边界(请参阅范例 1)。
- 范例 1(建议):假设模数值设为 360。
轴速度: 180
OnCompensation: 0
OffCompensation: 0
FirstOnPosition: 210
LastOnPosition: 340 - 范例 2 (不建议):假设模数值设为 360。最终的 first-on 位置将为 300 (210 + 0.5 * 180),最终的 last-on 位置将为 70 ((340 + 0.5 * 180) % 360),此即跨越模数边界(从 300 到 70)。
轴速度: 180
OnCompensation: 0.5
OffCompensation: 0.5
FirstOnPosition: 210
LastOnPosition: 340
- 范例 1(建议):假设模数值设为 360。
McCamSwitch 结构内的元素
B/E | 参数 | 类型 | 说明 |
---|---|---|---|
B | TrackNumber | INT | 轨道索引,以零为起点。 |
B | FirstOnPosition [使用者单位] | LREAL | 开关开启的位置。 |
B | LastOnPosition [使用者单位] | LREAL | 开关关闭的位置。 |
E | AxisDirection | INT |
轴方向,预设值为零。若选择一或二,开关仅在当轴在指定方向移动时有效。 正负:0;正方向: 1;负方向: 2。 |
E | CamSwitchMode | INT |
凸轮开关由轴的位置或时间控制,预设值为零。若选择位置 (position),需设定 FirstOnPosition 与 LastOnPosition;若选择时间 (Time),需设定 FirstOnPosition 与 Duration。 位置 (position): 0,时间 (Time):1。 |
E | Duration | TIME | 开关开启的时间,此功能在 CamSwitchMode 为 Time 时可用,每秒为一单位。 |
McTrack 结构内的元素
B/E | 参数 | 类型 | 说明 |
---|---|---|---|
E | OnCompensation | TIME | 在每个轨道的切换点之前或后打开开关(上升边缘)的时间长度。 若值为正,则开启将延迟;若值为负,则将提前开启。 |
E | OffCompensation | TIME | 在每个轨道的切换点之前或后关闭开关(下降边缘)的时间长度。若值为正,则关闭将延迟;若值为负,则将提前关闭。 |
E | Hysteresis [unit] | LREAL | 在轴离开该区域之前,从开关未打开或未关闭的切换点(正向和负向)的距离。 此可避免在开关点附近频繁切换。 |
此凸轮定义具有起点与终点,如此使用者可定义每一个凸轮的 FirstOnPosition 与 LastOnPosition(或时间),此功能或功能块类似机械凸轮,但具有额外的优点,您可为输出设置一个特定时间,并设定时间补偿和迟滞。
CamSwitchMode:可为位置或时间。
Duration:时长,凸轮开启的输出时长,时间补偿 (OnCompensation 与 OffCompensation) 可为正或负值,负值表示输出在开关位置到达前即变更。
Hysteresis:此参数可避免轴在切换点附近及实际位置在切换位置附近抖动时,输出不断切换的现象。Hysteresis 是 McTrack 的一部分,表示每个轨道都可设定不同的迟滞。
McCamSwitch 的范例
参数 | 型别 | 开关 01 | 开关 02 | 开关 03 | 开关 04 | ... | 开关 N |
---|---|---|---|---|---|---|---|
TrackNumber | INTEGER | 1 | 1 | 1 | 2 | ||
FirstOnPosition [单位] | LREAL | 2000 | 2500 | 4000 | 3000 | ||
LastOnPosition [单位] | LREAL | 3000 | 3000 | 6000 | -- | ||
AxisDirection | INTEGER | 1=正向 | 2=负向 | 0=双向 | 0=双向 | ||
CamSwitchMode | INTEGER | 0=位置 | 0=位置 | 0=位置 | 1=时间 | ||
Duration | LREAL | -- | -- | -- | 1.35 秒 |
McOutput 的范例
参数 | MC_OUTPUT[0] | MC_OUTPUT[1] | MC_OUTPUT[2] | - | - | - | MC_OUTPUT[31] |
---|---|---|---|---|---|---|---|
IsAxis | FALSE | FALSE | FALSE | - | - | - | FALSE |
Index | 0 | 0 | 0 | - | - | - | 0 |
BitOffset | 0 | 1 | 2 | - | - | - | 31 |
I/O 模组之范例
下图使用了上例 McCamSwitch 的值,不使用 On/OffCompensation 与 Hysteresis,此为当轴持续朝正向移动时的输出行为。
SetAxisCamSwitch – 正向
正向:输出行为
TrackNumber 1(开关 01, 02, 03)匹配到 McOutput[1];TrackNumber 2(开关 04)匹配到 McOutput[2]。当开关 01、开关 02、开关 03 被触发时,第一个 I/O 模组(索引 0)上的第二个输出(输出 1)即被开启。当开关 04 被触发时,第三个输出(输出 2)即被开启。
On/Off 补偿之范例
以下范例使用 OnCompensation -125ms 与 OffCompensation +250ms。
下图为当轴持续朝负向移动,且不使用 On/OffCompensation 与 Hysteresis 时的输出行为。
SetAxisCamSwitch – 负向
负向:输出行为
EnableMask
EnableMask 是一个含有 32 位元的 uint32 参数,每个位元都是一个 bool 值,可控制输出。输出可透过将相应的位元设为 TRUE 或 FALSE 来启用或停用,例如位元 0 控制 McOutput[0];位元 1 控制 McOutput[1],若位元 0 和位元 1 都设为 TRUE,其输出即被启用,意即当相对应的开关被触发时,其输出即被开启。若位元 0 和位元 1 都设为 FALSE,其输出即被停用,即使相对应的开关被触发时,其输出也不会被开启。
位元 | 位元 0 | 位元 1 | 位元 2 | 位元 3 | - | - | - | - | 位元 31 |
---|---|---|---|---|---|---|---|---|---|
值 | TRUE/FALSE | TRUE/FALSE | TRUE/FALSE | TRUE/FALSE | - | - | - | - | TRUE/FALSE |
McOutput 的范例
参数 | MC_OUTPUT[0] | MC_OUTPUT[1] | MC_OUTPUT[2] | - | - | - | MC_OUTPUT[31] |
---|---|---|---|---|---|---|---|
IsAxis | FALSE | FALSE | FALSE | - | - | - | FALSE |
Index | 0 | 0 | 0 | - | - | - | 0 |
BitOffset | 0 | 1 | 2 | - | - | - | 31 |
EnableMask 位元之范例 1
位元 0、1、2 为 TRUE,意即输出 0、1、2 被启用,当相对应的开关被触发时,输出即被开启。
位元 | 位元 0 | 位元 1 | 位元 2 | 位元 3 | - | - | - | - | 位元 31 |
---|---|---|---|---|---|---|---|---|---|
值 | TRUE | TRUE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
正向:输出行为
EnableMask 位元之范例 2
位元 0、2 为 TRUE,意即输出 0、2 被启用,当相对应的开关被触发时,仅有这 2 个输出会被开启。
位元 | 位元 0 | 位元 1 | 位元 2 | 位元 3 | - | - | - | - | 位元 31 |
---|---|---|---|---|---|---|---|---|---|
值 | TRUE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
正向:输出行为
EnableMask 位元之范例 3
所有位元均为 FALSE,意即所有输出均停用,即使相对应的开关被触发时,输出也不会被开启。
位元 | 位元 0 | 位元 1 | 位元 2 | 位元 3 | - | - | - | - | 位元 31 |
---|---|---|---|---|---|---|---|---|---|
值 |
FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
正向:输出行为
范例
KsCommandStatus EnableSwitches(INT Index) {
//Each track will control one output and can contain multiple switches
/*On compensation is a delay in seconds before the output
is turned on when a switch becomes active*/
/*Off compensation is a delay in seconds before the outout
is turned off when a switch becomes inactive*/
/*Hysteresis adds a minimum distance in between switches
to prevent an output from switching on and off*/
McTrack Tracks[2] = {
//OnCompensation OffCompensation Hysteresis
{ -0.125, 0.25, 0 },
{ 0, 0, 0 }
};
//Defines the output for each track
//The type selects between axes and modules. TRUE: Axis, FALSE: Module
//Index of the axis or module
//Offset of the output bit in the device output buffer
McOutput Outputs[2] = {
//Axis Index Offset
{ FALSE, 1, 0 },
{ TRUE, Index, 1 }
};
//Defines each switch.
//Index of the track the switch belongs to.
//Position at which the switch is enabled.
//Position at which the switch is disabled for distance switches.
//Direction in which the switch is triggered. 0: Both, 1: Positive, 2: Negative
//Switch mode. 0: Distance, 1: Time
//Duration in seconds the switch stays enabled. For time switches.
McCamSwitch Switches[4] = {
//TrackNumber FirstOnPosition LastOnPosition AxisDirection CamSwitchMode Duration
{ 1, 200, 800, 1, 0, 0 },
{ 1, 2500, 3000, 2, 0, 0 },
{ 1, 4000, 6000, 0, 0, 0 },
{ 2, 3000, 0, 0, 1, 1.35 }
};
KsCommandStatus camSwitch = SetAxisCamSwitch(
Index, //Index
4, //SwitchLength
Switches, //Switches
2, //TrackLength
Outputs, //Outputs
Tracks, //Tracks
3, //EnableMask, enabling track 1 and 2
mcSetValue //ValueSource
);
return camSwitch;
}
使用需求
RT | Win32 | |
---|---|---|
最低支援版本 | 4.0 | 4.0 |
标头档 | ksmotion.h | ksmotion.h |
程式库 | KsApi_Rtss.lib | KsApi.lib |
参见